package com.ph.irp.base.assistantmaterial.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialProductPurposeService;
import com.ph.irp.model.PBaseAssistantmaterialProductpurpose;

public class AssistantmaterialProductpurposeAction extends ActionSupport {

	private static final long serialVersionUID = 4764377778075548073L;
	// 领料用途service
	private PBaseAssistantmaterialProductPurposeService productPurposeService;
	// 领料用途list
	private List<PBaseAssistantmaterialProductpurpose> productpurposeList;
	// 领料用途model
	private PBaseAssistantmaterialProductpurpose productpurposeModel;
	// 接收选中复选框传递的数据
	private String[] rowlist = null;
	private String FORWARD;

	/**
	 * 动态查询领料用途
	 * 
	 * @return
	 */
	public String getProductPurposes() throws Throwable {
		if (productpurposeModel == null)
			productpurposeList = productPurposeService.getAllProductpurposes();
		else if (!productpurposeModel.getProductPurposeCode().trim().equals("")
				&& !productpurposeModel.getProductPurposeName().trim().equals(
						""))
			productpurposeList = productPurposeService.getProductpurposesByCodeAndName(
					productpurposeModel.getProductPurposeCode(),
					productpurposeModel.getProductPurposeName());
		else if (!productpurposeModel.getProductPurposeCode().trim().equals(""))
			productpurposeList = productPurposeService.getProductpurposesByCode(productpurposeModel
					.getProductPurposeCode());
		else if (!productpurposeModel.getProductPurposeName().trim().equals(""))
			productpurposeList = productPurposeService.getProductpurposesByName(productpurposeModel
					.getProductPurposeName());
		else
			productpurposeList = productPurposeService.getAllProductpurposes();
		productpurposeModel = null;
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 增加辅助物料领料用途
	 * 
	 * @param pbaseSettlement
	 * @return
	 */
	public String addProductPurpose() throws Throwable {
		this.productPurposeService.addProductpurpose(productpurposeModel);
		FORWARD = "success";
		return FORWARD;
	}
	
	/**
	 * 删除辅助物料领料用途
	 * 
	 * @return
	 */
	public String deleteProductPurpose() throws Throwable {

		this.productPurposeService.deleteProductpurpose(rowlist);

		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 修改辅助物料领料用途
	 * 
	 * @return
	 */
	public String updateProductPurposeInput() throws Throwable {

		int productpurposeId = Integer.valueOf((String) rowlist[0]);
		productpurposeModel = productPurposeService
				.getProductpurposeById(productpurposeId);
		FORWARD = "success";
		return FORWARD;
	}
	
	/**
	 * 修改辅助物料领料用途
	 * 
	 * @param pbaseSettlement
	 * @return
	 */
	public String updateProductPurpose() throws Throwable {
		this.productPurposeService.updateProductpurpose(productpurposeModel);
		FORWARD = "success";
		return FORWARD;
	}

	

	/**
	 * 选择辅助物料领料用途
	 * 
	 * @return
	 */
	public String selectProductPurpose() throws Throwable {

		this.getProductPurposes();

		FORWARD = "success";
		return FORWARD;
	}
	
	public String showProductPurpose() throws Throwable {
		productpurposeModel = null;
		this.getProductPurposes();
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * setters and getters for instance variables
	 * 
	 * @return
	 */

	public PBaseAssistantmaterialProductPurposeService getProductPurposeService() {
		return productPurposeService;
	}

	public void setProductPurposeService(
			PBaseAssistantmaterialProductPurposeService productPurposeService) {
		this.productPurposeService = productPurposeService;
	}

	public List<PBaseAssistantmaterialProductpurpose> getProductpurposeList() {
		return productpurposeList;
	}

	public void setProductpurposeList(
			List<PBaseAssistantmaterialProductpurpose> productpurposeList) {
		this.productpurposeList = productpurposeList;
	}

	public PBaseAssistantmaterialProductpurpose getProductpurposeModel() {
		return productpurposeModel;
	}

	public void setProductpurposeModel(
			PBaseAssistantmaterialProductpurpose productpurposeModel) {
		this.productpurposeModel = productpurposeModel;
	}

	public String[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(String[] rowlist) {
		this.rowlist = rowlist;
	}

}
